<%@ include file="IsStudent.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
try{
           String[] id = null;
            String[] title = null;
            int size = 0;

            DBCon db1 = new DBCon();
            size = db1.countProjects(",professor where professor.id = project.professorid and status='accepted' and project.id not in  (SELECT projectid FROM choosedprojects where studentid =" + session.getAttribute("id") + ")");
            id = new String[size];
            title = new String[size];
			String[] profName= new String[size];
            ResultSet res = db1.getProject(",professor where professor.id = project.professorid and status='accepted' and project.id not in  (SELECT projectid FROM choosedprojects where studentid =" + session.getAttribute("id") + ");");
            for (int i = 0; res.next(); i++) {
                id[i] = res.getString("project.id");
                title[i] = res.getString("title");
				profName[i] = res.getString("firstName")+" "+res.getString("lastName");
            }
            int size1 = db1.countProjectsChoosed(",professor where professor.id = project.professorid and choosedprojects.studentId =" + session.getAttribute("id") + " AND project.ID = choosedprojects.ProjectId");
            ResultSet res2 = db1.getProjectsChoosed(",professor where professor.id = project.professorid and choosedprojects.studentId =" + session.getAttribute("id") + " AND project.ID = choosedprojects.ProjectId order by priority");
            String[] id2 = new String[size1];
            String[] title2 = new String[size1];
			String[] profName2= new String[size1];
            for (int i = 0; res2.next(); i++) {
                id2[i] = res2.getString("project.id");
                title2[i] = res2.getString("title");
				profName2[i] = res2.getString("firstName")+" "+res2.getString("lastName");
            }
%>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript" src="js/project.js"></script>
        <script type="text/javascript" src="js/drag_drop.js"></script>
        <link rel="STYLESHEET" href="styles/project.css" type="text/css">
        <link rel="stylesheet" href="styles/control.css" type="text/css"/>
        <script type="text/javascript">
            var count = <%=size1%>;
            function check() {
                count =0;
                var it = new Array();
                                                  <%
            int x;
            for (x = 0; x < id.length; x++) {
                out.println("it[" + x + "] = document.getElementById('" + id[x] + "');");
            }
            for (; x < id2.length + id.length; x++) {
                out.println("it[" + x + "] = document.getElementById('" + id2[x - id.length] + "');");
            }
%>
    
    for(var i=0;i<it.length;i++)
        {
            if(it[i] != null && it[i].parentNode.id == "DragContainer5")
                {
                    count++;
                }
            }
            var links = document.body.getElementsByTagName("a");
            for(var i=0;i<links.length;i++)
                {
                    links[i].onclick = function() {
                        return confirm("You made changes on choosing project\nDo you want to discard it? if you do not click save changes button");
                    }
                }
            return true;
            
            }
            function save()
            {
                var div = document.getElementById("DragContainer5");
                var showOut = document.getElementById("finalForm");
                var divs = div.getElementsByTagName("div");
                var x = "<form name='finalForm1' id='ff' action='saveChoices.jsp' method='get'>";
                for(i=0;i<divs.length;i++)
                    {
                        x += "<input type='hidden' name='"+ (i+1) +"' value='"+ divs[i].id +"'>";
                    }
                    x += "</form>";
                    showOut.innerHTML = x;
                    document.finalForm1.submit();
                }
        </script>
        <%@ include file="../master/head.jsp"%>
		 <style>
			  .DragBox {
				   font-size:15px;
					font-weight: bold;
				   }
			  B.creat
			   {
									   font-size:12px;
					color: blue;
					 font-weight: normal;
				   }
			  B.proj
			   {
									   font-size:12px;
					color: red;
					 					 font-weight: normal;
				   }
					
		  </style>

    </head>
    <body>
        <div id="container">
            <div id="wrapper">
                <div id="sidebar">
                    <div id="sb_top"><%@ include file="../master/sbTop.jsp"%></div>
                    <div class="sb_content"><!--##########--> <!-- Start Menu --> <%@ include
                  file="../master/studentMenu.jsp"%> <!-- Profile -->
<%@ include file="../master/profile.jsp"%> <!-- links -->
<%@ include file="../master/links.jsp"%>
                        <div class="copyright"><%@ include file="../master/copyright.jsp"%>
                        </div>
                        
                    </div>
                <!-- /sb_content --></div>
                <!-- /sidebar --> <!-- Top -->
                <div id="header"><%@ include file="../master/header.jsp"%>
                </div>
                
                
                <!-- Start main content -->
                <div id="content">
                    <div id="intro">
                        <div class="intro_t">
                            <h1><span>..</span>Welcome to<span>..</span></h1>
                            <h2>student project managment system</h2>
                          
                        </div>
                    </div>
                    <h1>Your Choices</h1>
                    <%@ page import="java.sql.*,database.*" %>
                    <%
            DBCon db = new DBCon();
            
            String control = db.getControlValue("choose_project");
            
            if(control.equals("true"))
            {
            if (db == null) {
                out.print("asd");
            } else {
                ResultSet res1 = db.getSProject((String) session.getAttribute("id"));
                if (res1.next())//print Assigned projects
                {
                    out.println("<h2>Your Project is <a href='javascript:openWindow(" + res1.getString("ID") + ")' >" + res1.getString(2) + "</a></h2>");
                } else //print all projects
                {
                    // Execute query and save results.
                    res1 = db.getProjectsValidated();
                    %>
                    <div><a href="myChoiceClassic.jsp">Classic Style?</a></div>					
                    <div id='Demo4' width="100%">
                        <center><table> <tr><td><h2>All Valid Projects</h2></td><td width=150 ></td><td><h2>My Orderd Choices </h2></td></tr></table></center>
                        <DIV class=DragContainer id=DragContainer4 overClass="OverDragContainer">
                            <%
                                for (int i = 0; i < id.length; i++) {
                            %>
                            <DIV class=DragBox id="<%=id[i]%>" overClass="DragBox" dragClass="DragBox" ondblclick="openWindow(<%=id[i]%>)" height="100%">
							<%=title[i]%>
							<br><B class='creat'>created by:</B><b class = 'proj'><%=profName[i]%></b>
							 </DIV>
                            <%
                                }
                            %>
                        </DIV>
                        <DIV class=DragContainer id=DragContainer5 overClass="OverDragContainer">
                            <%
                                for (int i = 0; i < id2.length; i++) {
                            %>
                            <DIV class=DragBox id="<%=id2[i]%>" projectID = "pr<%=id2[i]%>" overClass="DragBox" dragClass="DragBox" ondblclick="openWindow(<%=id2[i]%>)">
							<%=title2[i]%>
							<br><B class='creat'>created by:</B><b class = 'proj'><%=profName2[i]%></b>
							</DIV>
                            <%
                                }
                            %>
                        </DIV>
                        <input type="button" value="save Choices" onclick="save()">	
                    </div>
                    <div id="finalForm"></div>
                    <%
                }
            }
	    }else
                {%>
                <br/><br/><center><h2> This service is not availabe now </h2></center>
            <%}
            }
catch(SQLException e)
{
    response.sendRedirect("../connectionFailed.jsp?"+e);
}

                    %>
                    
                </div>
            <!-- /content --></div>
            <!-- /wrapper -->
            <div class="clear">&nbsp;</div>
        <!-- Important! Fix the problem of height in Firefox --></div>
        <!-- /Container -->

        
    </body>
</html>
